package de.so.myteach;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import de.so.myteach.dummy.DummyContent;
import de.so.myteach.dummy.DummyContent.DummyItem;
import java.util.List;

public class PupilListFragment extends ListFragment
{
  private static final String STATE_ACTIVATED_POSITION = "activated_position";
  private static Callbacks sDummyCallbacks = new Callbacks()
  {
    public void onItemSelected(String paramString)
    {
    }
  };
  private int mActivatedPosition = -1;
  private Callbacks mCallbacks = sDummyCallbacks;

  private void setActivatedPosition(int paramInt)
  {
    if (paramInt == -1) {
      getListView().setItemChecked(this.mActivatedPosition, false);
    }
    else
    {
      this.mActivatedPosition = paramInt;
      getListView().setItemChecked(paramInt, true);
    }
  }

  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    if (!(paramActivity instanceof Callbacks))
      throw new IllegalStateException("Activity must implement fragment's callbacks.");
    this.mCallbacks = ((Callbacks)paramActivity);
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setListAdapter(new ArrayAdapter(getActivity(), R.layout.simple_list_item_1, R.id.text1, DummyContent.ITEMS));
    /*if ((paramBundle != null)) {
    	Toast.makeText(getActivity(), paramBundle.getInt("list_id"), Toast.LENGTH_SHORT).show();
    	setListAdapter(new ArrayAdapter(getActivity(), R.layout.simple_list_item_2, R.id.text1, DummyContent.ITEMS));
    }*/
  }

  public void onDetach()
  {
    super.onDetach();
    this.mCallbacks = sDummyCallbacks;
  }

  public void onListItemClick(ListView paramListView, View paramView, int paramInt, long paramLong)
  {
    super.onListItemClick(paramListView, paramView, paramInt, paramLong);
    this.mCallbacks.onItemSelected(((DummyItem)DummyContent.ITEMS.get(paramInt)).id);
  }

  public void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
    if (this.mActivatedPosition != -1)
      paramBundle.putInt("activated_position", this.mActivatedPosition);
  }

  public void onViewCreated(View paramView, Bundle paramBundle)
  {
    super.onViewCreated(paramView, paramBundle);
    if ((paramBundle != null) && (paramBundle.containsKey("activated_position")))
      setActivatedPosition(paramBundle.getInt("activated_position"));
  }

  public void setActivateOnItemClick(boolean paramBoolean)
  {
    ListView localListView = getListView();
    localListView.setChoiceMode(0);
    if (paramBoolean)
      localListView.setChoiceMode(1);
    
  }
  
  public void setChanged() {
	  //setListAdapter(new ArrayAdapter(getActivity(), R.layout.simple_list_item_2, R.id.text1, DummyContent.ITEMS));
	  //((ArrayAdapter)this.getListAdapter()).notifyDataSetChanged();
  }

  public static abstract interface Callbacks
  {
    public abstract void onItemSelected(String paramString);
  }
}